<!DOCTYPE html>





<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico?v=7.4.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=7.4.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico?v=7.4.0">
  <link rel="mask-icon" href="/images/logo.svg?v=7.4.0" color="#222">

<link rel="stylesheet" href="/css/main.css?v=7.4.0">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.4.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.json',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="git的配置 安装git 安装完成后，需要设置自己的用户名和email，在命令行输入：  12git config --global user.name &quot;levon&quot;git config --global user.email &quot;levonfly@gmail.com&quot;  git和目录绑定 在一个目录里可以通过git init命令把这个目录变成Git可以管理的仓库,然后通过以下命令绑定提交的地址">
<meta name="keywords" content="git">
<meta property="og:type" content="article">
<meta property="og:title" content="git实用操作总结">
<meta property="og:url" content="https://unix2dos.github.io/p/42eae4e7.html">
<meta property="og:site_name" content="Levon&#39;s Blog">
<meta property="og:description" content="git的配置 安装git 安装完成后，需要设置自己的用户名和email，在命令行输入：  12git config --global user.name &quot;levon&quot;git config --global user.email &quot;levonfly@gmail.com&quot;  git和目录绑定 在一个目录里可以通过git init命令把这个目录变成Git可以管理的仓库,然后通过以下命令绑定提交的地址">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-09-27T15:36:51.135Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="git实用操作总结">
<meta name="twitter:description" content="git的配置 安装git 安装完成后，需要设置自己的用户名和email，在命令行输入：  12git config --global user.name &quot;levon&quot;git config --global user.email &quot;levonfly@gmail.com&quot;  git和目录绑定 在一个目录里可以通过git init命令把这个目录变成Git可以管理的仓库,然后通过以下命令绑定提交的地址">
  <link rel="canonical" href="https://unix2dos.github.io/p/42eae4e7">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>git实用操作总结 | Levon's Blog</title>
  








  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
  <div class="container use-motion">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Levon's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">微信:  L6241425</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>时光</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-categories">
      
    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-tags">
      
    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger">
        
          <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
      </li>
    
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
      <article itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block post">
    <link itemprop="mainEntityOfPage" href="https://unix2dos.github.io/p/42eae4e7.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Levon">
      <meta itemprop="description" content="Never Give Up">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Levon's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">git实用操作总结

          
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2016-12-16 11:17:48" itemprop="dateCreated datePublished" datetime="2016-12-16T11:17:48+08:00">2016-12-16</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-09-27 23:36:51" itemprop="dateModified" datetime="2019-09-27T23:36:51+08:00">2019-09-27</time>
              </span>
            
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/2-linux系统/" itemprop="url" rel="index"><span itemprop="name">2-linux系统</span></a></span>

                
                
                  ，
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/2-linux系统/git/" itemprop="url" rel="index"><span itemprop="name">git</span></a></span>

                
                
              
            </span>
          

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
        
      
      <span class="post-meta-item-text">Disqus：</span>
    
    <a title="disqus" href="/p/42eae4e7.html#comments" itemprop="discussionUrl"><span class="post-comments-count disqus-comment-count" data-disqus-identifier="p/42eae4e7.html" itemprop="commentCount"></span></a>
  </span>
  
  
          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
              
                <span class="post-meta-item-text">本文字数：</span>
              
              <span>3.1k</span>
            </span>
          
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
              
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              
              <span>3 分钟</span>
            </span>
          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="git的配置"><a href="#git的配置" class="headerlink" title="git的配置"></a>git的配置</h3><ol>
<li>安装git</li>
<li>安装完成后，需要设置自己的用户名和email，在命令行输入：</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name <span class="string">"levon"</span></span><br><span class="line">git config --global user.email <span class="string">"levonfly@gmail.com"</span></span><br></pre></td></tr></table></figure>

<h3 id="git和目录绑定"><a href="#git和目录绑定" class="headerlink" title="git和目录绑定"></a>git和目录绑定</h3><ol>
<li>在一个目录里可以通过git init命令把这个目录变成Git可以管理的仓库,然后通过以下命令绑定提交的地址</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote add origin https://github.com/unix2dos/unix2dos.github.io</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>git clone 地址 就会创建目录和地址绑定<a id="more"></a>

</li>
</ol>
<h3 id="git的基础操作"><a href="#git的基础操作" class="headerlink" title="git的基础操作"></a>git的基础操作</h3><ol>
<li><p>命令git add           把文件添加到仓库</p>
</li>
<li><p>命令git commit       把文件提交到仓库</p>
</li>
<li><p>命令git pull       把远程仓库拉取文件</p>
</li>
<li><p>命令git push       把文件提交到远程仓库</p>
</li>
<li><p>命令git log           查看git提交日志</p>
</li>
<li><p>如果嫌输出信息太多, 可以加上–pretty=oneline参数. 另外也可以花式log输出, git lg查看下</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global alias.lg <span class="string">"log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset' --abbrev-commit --date=relative"</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>命令git diff 查看版本之间文件修改变化</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git diff 87b91b6 f9b3075 [--name-only]加上可以只看文件名字</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h3 id="git-回滚版本"><a href="#git-回滚版本" class="headerlink" title="git 回滚版本"></a>git 回滚版本</h3><p>在Git中，用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来，所以写成HEAD~100。</p>
<ol>
<li><p>回滚到上一个版本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard HEAD^</span><br></pre></td></tr></table></figure>
</li>
<li><p>回滚到任意一个版本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard 版本号(通过git <span class="built_in">log</span>查看)</span><br></pre></td></tr></table></figure>
</li>
<li><p>如果git回滚到历史版本后, git log只能看历史版本再以前的版本号, 不到未来的版本号怎么办?</p>
<blockquote>
<p>git 提供了一个命令git reflog用来记录你的每一次命令</p>
</blockquote>
</li>
</ol>
<h3 id="git回滚文件"><a href="#git回滚文件" class="headerlink" title="git回滚文件"></a>git回滚文件</h3><ul>
<li>查看文件的修改记录</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">log</span> config.h</span><br></pre></td></tr></table></figure>

<ul>
<li>查看文件版本的差别</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git diff a3551 fd681 config.h</span><br></pre></td></tr></table></figure>

<ul>
<li>回退到指定的版本</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset fd681 config.h</span><br></pre></td></tr></table></figure>

<ul>
<li>提交到本地参考</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit -m <span class="string">"revert old file because commmit have a bug"</span></span><br></pre></td></tr></table></figure>

<ul>
<li>更新到工作目录</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout config.h</span><br></pre></td></tr></table></figure>

<ul>
<li>提交到远程仓库</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push origin master</span><br></pre></td></tr></table></figure>

<h3 id="git撤销操作"><a href="#git撤销操作" class="headerlink" title="git撤销操作"></a>git撤销操作</h3><ul>
<li>git修改文件后, 还没有add, commit.  这时撤销文件修改, 即回到上一版本的内容</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -- file</span><br></pre></td></tr></table></figure>

<p>命令中的–很重要，没有–，就变成了“创建一个新分支”的命令，我们在后面的分支管理中会再次遇到git checkout命令。</p>
<ul>
<li>git add 文件后撤销add操作</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset HEAD file</span><br></pre></td></tr></table></figure>

<h3 id="git解决冲突"><a href="#git解决冲突" class="headerlink" title="git解决冲突"></a>git解决冲突</h3><ol>
<li><p>建议手动解决冲突</p>
</li>
<li><p>命令行可以使用别人或自己的版本</p>
</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout --theirs/--ours  file</span><br></pre></td></tr></table></figure>

<h3 id="git全局配置"><a href="#git全局配置" class="headerlink" title="git全局配置"></a>git全局配置</h3><ul>
<li>中文不再显示8进制  git status显示中文</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global core.quotepath <span class="literal">false</span></span><br></pre></td></tr></table></figure>

<ul>
<li>设置代理, 因为国内一些原因下载的很慢</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global http.proxy <span class="string">'localhost:8123'</span></span><br><span class="line">git config --global --<span class="built_in">unset</span> http.proxy</span><br></pre></td></tr></table></figure>

<ul>
<li>git区分文件大小写</li>
</ul>
<p>git默认不区分文件大小写,导致文件名改了以后git状态没有改变,需要设置一下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config core.ignorecase false</span><br></pre></td></tr></table></figure>

<h3 id="git-分支操作"><a href="#git-分支操作" class="headerlink" title="git 分支操作"></a>git 分支操作</h3><p>查看分支：git branch</p>
<p>创建分支：git branch <name></name></p>
<p>切换分支：git checkout <name></name></p>
<p>创建+切换分支：git checkout -b <name></name></p>
<p>合并某分支到当前分支：git merge <name></name></p>
<p>删除分支：git branch -d <name></name></p>
<h3 id="git-标签操作"><a href="#git-标签操作" class="headerlink" title="git 标签操作"></a>git 标签操作</h3><p>命令git tag <name>用于新建一个标签，默认为HEAD，也可以指定一个commit id；</name></p>
<p>git tag -a <tagname> -m “blablabla…”可以指定标签信息；</tagname></p>
<p>git tag -s <tagname> -m “blablabla…”可以用PGP签名标签；</tagname></p>
<p>命令git tag可以查看所有标签。</p>
<p>命令git push origin <tagname>可以推送一个本地标签；</tagname></p>
<p>命令git push origin –tags可以推送全部未推送过的本地标签；</p>
<p>命令git tag -d <tagname>可以删除一个本地标签；</tagname></p>
<p>命令git push origin :refs/tags/<tagname>可以删除一个远程标签。</tagname></p>
<h3 id="git-合并-commit"><a href="#git-合并-commit" class="headerlink" title="git 合并 commit"></a>git 合并 commit</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">git rebase -i &quot;合并前一个版本号&quot;// 合并前一个 版本号</span><br><span class="line"></span><br><span class="line">	pick 是用commit</span><br><span class="line">	squash 是合并前一个</span><br><span class="line"></span><br><span class="line">:wq 退出修改合并后的 commit log</span><br><span class="line"></span><br><span class="line">git rebase --abort 如果出现失误来撤销</span><br></pre></td></tr></table></figure>

<h3 id="github-fork后更新源仓库的代码"><a href="#github-fork后更新源仓库的代码" class="headerlink" title="github fork后更新源仓库的代码"></a>github fork后更新源仓库的代码</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git remote add upstream https://github.com/golang/go</span><br><span class="line">git remote -v</span><br><span class="line">git fetch upstream</span><br><span class="line">git merge upstream/master</span><br></pre></td></tr></table></figure>

<h3 id="git-增加-远程仓库-orgin-名字不一样"><a href="#git-增加-远程仓库-orgin-名字不一样" class="headerlink" title="git 增加 远程仓库 orgin(名字不一样)"></a>git 增加 远程仓库 orgin(名字不一样)</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git remote add github git@github.com:unix2dos/dht.git</span><br><span class="line">git push github master</span><br></pre></td></tr></table></figure>

<h3 id="git-分支修改名字"><a href="#git-分支修改名字" class="headerlink" title="git 分支修改名字"></a>git 分支修改名字</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -m 原名 新名</span><br></pre></td></tr></table></figure>

<h3 id="git撤销操作-1"><a href="#git撤销操作-1" class="headerlink" title="git撤销操作"></a>git撤销操作</h3><ul>
<li>git push 后撤销</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git revert &lt;hash&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>commit消息撤销</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit --amend -m &apos;新的消息&apos;</span><br></pre></td></tr></table></figure>

<ul>
<li>回滚文件的改动(未有commit) </li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -- &lt;filename&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li>回滚版本</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard &lt;hash&gt;  (--hard强制内容回归,如果修改内容保留不加此选项)</span><br></pre></td></tr></table></figure>

<ul>
<li>停止追踪一个文件</li>
</ul>
<p>你偶然把application.log加到代码库里了，现在每次你运行应用，Git都会报告在application.log里有未提交的修改。你把 *.log放到了.gitignore文件里，可文件还是在代码库里，你怎样才能让Git“撤销”对这个文件的追踪呢？</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git rm --cached application.log</span><br></pre></td></tr></table></figure>

<h3 id="git-lg-完美显示"><a href="#git-lg-完美显示" class="headerlink" title="git lg 完美显示"></a>git lg 完美显示</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global alias.lg &quot;log --color --graph --pretty=format:&apos;%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset&apos; --abbrev-commit&quot;</span><br></pre></td></tr></table></figure>
    </div>

    
    
    
        
      
        <div id="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作, 一个耿直的笑脸~</div>
  <button id="reward-button" disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
        
      
      <div style="display: inline-block">
        <img src="/images/wechatpay.jpg" alt="Levon 微信支付">
        <p>微信支付</p>
      </div>
        
      
      <div style="display: inline-block">
        <img src="/images/alipay.jpg" alt="Levon 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/git/" rel="tag"># git</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/p/30321ed4.html" rel="next" title="xcode自定义Eclipse中常用的快捷键">
                  <i class="fa fa-chevron-left"></i> xcode自定义Eclipse中常用的快捷键
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/p/1e4be646.html" rel="prev" title="c++11的模板类型判断std::is_same和std::decay">
                  c++11的模板类型判断std::is_same和std::decay <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          
    
    
  <div class="comments" id="comments">
    <div id="disqus_thread">
      <noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
    </div>
  </div>
  
  

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">
        
        
        
        
      

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#git的配置"><span class="nav-number">1.</span> <span class="nav-text">git的配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git和目录绑定"><span class="nav-number">2.</span> <span class="nav-text">git和目录绑定</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git的基础操作"><span class="nav-number">3.</span> <span class="nav-text">git的基础操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-回滚版本"><span class="nav-number">4.</span> <span class="nav-text">git 回滚版本</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git回滚文件"><span class="nav-number">5.</span> <span class="nav-text">git回滚文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git撤销操作"><span class="nav-number">6.</span> <span class="nav-text">git撤销操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git解决冲突"><span class="nav-number">7.</span> <span class="nav-text">git解决冲突</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git全局配置"><span class="nav-number">8.</span> <span class="nav-text">git全局配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-分支操作"><span class="nav-number">9.</span> <span class="nav-text">git 分支操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-标签操作"><span class="nav-number">10.</span> <span class="nav-text">git 标签操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-合并-commit"><span class="nav-number">11.</span> <span class="nav-text">git 合并 commit</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#github-fork后更新源仓库的代码"><span class="nav-number">12.</span> <span class="nav-text">github fork后更新源仓库的代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-增加-远程仓库-orgin-名字不一样"><span class="nav-number">13.</span> <span class="nav-text">git 增加 远程仓库 orgin(名字不一样)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-分支修改名字"><span class="nav-number">14.</span> <span class="nav-text">git 分支修改名字</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git撤销操作-1"><span class="nav-number">15.</span> <span class="nav-text">git撤销操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-lg-完美显示"><span class="nav-number">16.</span> <span class="nav-text">git lg 完美显示</span></a></li></ol></div>
        
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
      src="/images/avatar.jpg"
      alt="Levon">
  <p class="site-author-name" itemprop="name">Levon</p>
  <div class="site-description" itemprop="description">Never Give Up</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">127</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        <span class="site-state-item-count">34</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        <span class="site-state-item-count">76</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/unix2dos" title="GitHub &rarr; https://github.com/unix2dos" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:levonfly@gmail.com" title="E-Mail &rarr; mailto:levonfly@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://twitter.com/levonfly" title="Twitter &rarr; https://twitter.com/levonfly" rel="noopener" target="_blank"><i class="fa fa-fw fa-twitter"></i>Twitter</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://weibo.com/l6241425" title="Weibo &rarr; https://weibo.com/l6241425" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
      </span>
    
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Levon</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">507k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">7:41</span>
</div>

        












        
      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js?v=3.1.0"></script>
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="/js/utils.js?v=7.4.0"></script><script src="/js/motion.js?v=7.4.0"></script>
<script src="/js/schemes/pisces.js?v=7.4.0"></script>

<script src="/js/next-boot.js?v=7.4.0"></script>



  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>








  <script src="/js/local-search.js?v=7.4.0"></script>














  

  

  

<script>
  function loadCount() {
    var d = document, s = d.createElement('script');
    s.src = 'https://levonfly.disqus.com/count.js';
    s.id = 'dsq-count-scr';
    (d.head || d.body).appendChild(s);
  }
  // defer loading until the whole page loading is completed
  window.addEventListener('load', loadCount, false);
</script>
<script>
  function disqus_config() {
    this.page.url = "https://unix2dos.github.io/p/42eae4e7.html";
    this.page.identifier = "p/42eae4e7.html";
    this.page.title = 'git实用操作总结';};
  function loadComments() {
    if (window.DISQUS) {
      DISQUS.reset({
        reload: true,
        config: disqus_config
      });
    } else {
      var d = document, s = d.createElement('script');
      s.src = 'https://levonfly.disqus.com/embed.js';
      s.setAttribute('data-timestamp', '' + +new Date());
      (d.head || d.body).appendChild(s);
    }
  }
    window.addEventListener('load', loadComments, false);
  
</script>

</body>
</html>
